﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="Scripts/jquery-3.3.1.min.js"></script>
    <script src="Scripts/jquery.signalR-2.2.2.js"></script>
    <script src="/signalr/hubs" type="text/javascript"></script>
</head>
<body>
    <ul id="ulist"></ul>
    <div id="msg"></div>
    组名：  <input type="text" id="groupName" /><button id="btnGroup">加入Group</button><br />
    组名：  <input type="text" id="gName" /><input type="text" id="groupContent" /><button id="btnSendGroup">发送Group内容</button><br />
    <script>

        $.connection.groupHub.client.onMessage = function (msg) {
            $("<li>msg:" + msg + "</li>").appendTo($("#ulist"));
        };

        $.connection.groupHub.client.onMessage1 = function (msg) {
            $("<li>msg1:" + msg + "</li>").appendTo($("#ulist"));
        };

        $.connection.hub.start().done(function () {
            $("#msg").text("done");
        }).fail(function () {
            $("#msg").text("fail");
            });

        $("#btnGroup").click(function () {
            var groupName = $("#groupName").val();
            $.connection.groupHub.server.addGroup(groupName);
        });

        $("#btnSendGroup").click(function () {
            var gName = $("#gName").val();
            var groupContent = $("#groupContent").val();
            $.connection.groupHub.server.sendGroupMsg(gName, groupContent);
        });
    </script>
</body>
</html>